<!--
 * @Author: 白印潇 bai_yinxiao@163.com
 * @Date: 2023-03-08 15:38:27
 * @LastEditors: 白印潇 bai_yinxiao@163.com
 * @LastEditTime: 2023-03-28 16:11:29
 * @FilePath: /shortRent-ui/src/views/risk/credit/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="app-container">

    <div class="customer_card_1">
      账户余额:
      <span style="font-size: 30px;font-weight: bold;margin: 0 20px 0 5px;">{{ balance }}元</span>
      <el-button type="primary" size="mini" @click="goRecord">充值及消费记录</el-button>
    </div>

    <div class="custom_card_0">
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" size="small">
        <el-form-item label="客户姓名" prop="memberName">
          <el-input v-model="queryParams.memberName" placeholder="请输入客户姓名" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="联系电话" prop="memberPhone">
          <el-input v-model="queryParams.memberPhone" placeholder="请输入联系电话" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item label="客户类型" prop="memberType">
          <el-select v-model="queryParams.memberType" placeholder="请选择客户类型" clearable>
            <el-option label="个人" :value="2" />
            <el-option label="企业" :value="1" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          class="first-plain-btn" size="medium"  @click="handleQueryCredit">反欺诈查询</el-button>
      </el-col>
    </el-row>
    <div>
      <el-table v-loading="loading" :data="basicList" stripe
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }" border>
        <template slot="empty">
          <el-empty :image-size="50" description="暂无反欺诈工单"></el-empty>
        </template>
        <el-table-column label="客户姓名" align="center">
          <template v-slot="{ row }">
            {{ row.member.memberType == 1 ? row.member.enterpriseName : row.member.memberName }}
          </template>
        </el-table-column>
        <el-table-column label="联系电话" align="center">
          <template v-slot="{ row }">
            {{ row.member.contactPhone }}
          </template>
        </el-table-column>
        <el-table-column label="客户类型" align="center">
          <template v-slot="{ row }">
            {{ row.member.memberType == 1 ? "企业" : "个人" }}
          </template>
        </el-table-column>
        <el-table-column label="提交人" align="center" prop="createUserName" />
        <el-table-column label="查询时间" align="center" prop="queryTime" />
        <el-table-column label="查询结果" align="center">
          <template v-slot="{ row }">
            <!-- 查询成功 -->
            <template v-if="row.queryStatus == 2">
              <span v-if="row.abnormalCount != null && row.abnormalCount > 0" style="color: red;">
                {{ row.abnormalCount }}项异常
              </span>
              <span v-else style="color: green;">
                正常
              </span>
            </template>
            <template v-else>
              {{ row.queryStatus | illegalQueryStatus | filterNull }}
            </template>

          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="160">
          <template slot-scope="scope">
            <el-button size="small" type="text" @click="handleDetail(scope.row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div v-show="total > 0" style="background-color: #fff;padding-bottom: 10px; margin-top: 10px;">
        <pagination :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
          @pagination="getList" />
      </div>
    </div>

    <!-- 充值消费记录 -->
    <record-list ref="recordList"></record-list>

  </div>
</template>

<script>
import * as creditApi from '@/api/credit/credit';
import { accountBalanceInfo } from '@/api/car/illegal';
import RecordList from './components/recordList.vue';
export default {
  name: 'Risk',
  components: {
    RecordList

  },
  data() {
    return {
      // 账户余额
      balance: 0.00,
      // 加载标识
      loading: false,
      // 总条数
      total: 0,
      // 征信工单数据
      basicList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        memberName: '',
        memberPhone: '',
        memberType: ''
      }
    }
  },
  created() {
    this.getAccountInfo();
    this.getList()
  },
  activated() {
    this.getAccountInfo();
    this.getList()
  },
  methods: {
    // 搜索
    handleQuery() {
      this.refrehList();
    },
    // 重置
    resetQuery() {
      this.$refs.queryForm.resetFields();
      this.refrehList();
    },
    // 刷新工单列表
    refrehList() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 查询征信工单列表 */
    getList() {
      this.loading = true
      creditApi.creditWorkList(this.queryParams).then(res => {
        this.basicList = res.rows;
        this.total = res.total;
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 充值及消费记录
    goRecord() {
      this.$refs.recordList.show();
    },
    // 征信查询
    handleQueryCredit() {
      this.$router.push({ name: 'creditAdd', query: { type: 0 } })
    },

    // 查看
    handleDetail(item) {
      if (item.queryStatus == 2) {//查询成功
        this.$router.push({ name: 'creditDetail', query: { id: item.id } });
      } else {
        if (item.queryStatus < 2) { //查询中
          this.$message({
            message: '抱歉,征信工单查询中,请稍后查看',
            type: 'warning'
          });
        } else {
          this.$message({
            message: '抱歉,征信查询失败,请重新提交工单',
            type: 'error'
          });
        }

      }

    },


    // 获取账户余额信息
    getAccountInfo() {
      accountBalanceInfo().then(res => {
        this.balance = res.data.balance;
      })
    }




  },
}
</script>

<style scoped>
.customer_card_1 {
  background-color: #fff;
  padding: 30px;
  margin: 15px 0;
  display: flex;
  flex-direction: row;
  align-items: center;
}
</style>
